package com.zhu.ttwords;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

import com.zhu.ttwords.bean.AppBean;

/**
 * Created by KnightYe on 2015/4/4.
 */
public class TTWORDS extends Application {
    public static final String DATABASE_NAME = "TTWORDS.db";
    public static final String DATABASE_DIR = "TTWORDS/database";
    public static final String SP_SETTING = "setting";
    public static final String SP_VERSION_NAME = "VERSION_NAME";
    public static final String SP_VERSION_CODE = "VERSION_CODE";
    public static final String SP_STUDY_GROUP = "STUDY_GROUP";
    public static final String SP_STUDY_BOOK = "STUDY_BOOK";

    public static final String SQL_STUDY_INIT_STUDY = "select wid as WID,wcontent as CONTENT,wpos as POS,wexplain as EXPLAIN,wprono as PRONO" +
            " from TT_WORD where wid in(select WID from TT_BOOK_DIR WHERE BID = ? LIMIT ?);";
    //默认设置
    public static final int DEFAULT_STUDY_GROUP = 10;
    public static final int DEFAULT_STUDY_BOOK = 0;

    private static SharedPreferences sp;
    private static AppBean appSetting;
    private static int versionCode;
    private static String versionName;

    @Override
    public void onCreate() {
        try {
            PackageInfo pinfo = getPackageManager().getPackageInfo(getPackageName(),
                    PackageManager.GET_CONFIGURATIONS);
            versionName = pinfo.versionName;
            versionCode = pinfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        sp = getSharedPreferences(SP_SETTING, MODE_PRIVATE);
        appSetting = new AppBean(sp,
                versionCode,
                versionName,
                sp.getInt(SP_STUDY_GROUP, DEFAULT_STUDY_GROUP),
                sp.getInt(SP_STUDY_BOOK, DEFAULT_STUDY_BOOK));

    }

    public static AppBean getAppSetting() {
        return appSetting;
    }

    public static int getVersionCode() {
        return versionCode;
    }

    public static String getVersionName() {
        return versionName;
    }

    public static SharedPreferences getSp() {
        return sp;
    }

}
